# -*- conding:UTF-8 -*-

'''
@ Project: P8 flask_progect
@ File: output_json.py
@ Author: 罗婷
@ Date：2022/6/21 18:53

'''

from json import dumps
from flask import make_response, current_app

def my_output_json(data, code, headers=None):

    settings = current_app.config.get('RESTFUL_JSON', {})

    if current_app.debug:
        settings.setdefault('indent', 4)

    # 重写返回的data格式  以下为示例
    if 'message' not in data:
        data = {
            'message': 'ok',
            'data': data
        }


    dumped = dumps(data, **settings) + "\n"

    resp = make_response(dumped, code)
    resp.headers.extend(headers or {})
    return resp






